//
//  ZZVisitorViewController.swift
//  web
//
//  Created by 张卓 on 2017/1/17.
//  Copyright © 2017年 ZZ. All rights reserved.
//

import UIKit

//访客视图基类
//如果未登录.显示的是访客视图. VisitorView
//如果登录,显示的是列表. tableView

class ZZVisitorViewController: UIViewController {
    
    //判断用户是否已登录
    let isLogin:Bool = ZZOAuthViewModel.shared.isLogin
    //定义访客视图
    var visitorView:ZZVisitorView?
    
    //列表
    let tableView = UITableView()
    
    override func loadView() {
        //登录
        if isLogin {
//            super.loadView()
            view = tableView
        }else {
            //未登录
            
            setupVisitorView()
        }
    }
    //实例化visitorView
    private func setupVisitorView(){
        setupNav()
        visitorView = ZZVisitorView()
        
//        2. 实例化闭包
        visitorView?.closure = {[weak self] in
            //4. 闭包回调
//            print("00")
            self?.loginClick()
        }
        view = visitorView
        
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
    }

    
    
    //设置导航
    private func setupNav() {
        //左侧
        navigationItem.leftBarButtonItem = UIBarButtonItem(image: nil, title: "登录", target: self, action: #selector(loginClick))
        
        //右侧
        navigationItem.rightBarButtonItem = UIBarButtonItem(image: nil, title: "注册", target: self, action: #selector(loginClick))
    }
    
    @objc private func loginClick () {
        
        print("按钮点击")
        
        let oauthVC = ZZOAuthViewController()
        
        present(UINavigationController(rootViewController:oauthVC), animated: true, completion: nil)
        
    }
    
    
    
    
    
    
    
    
    
    
    

}
